package wens.pig.base.plugin.form;

import dm.jdbc.util.StringUtil;
import kd.bos.entity.datamodel.events.PropertyChangedArgs;
import kd.bos.form.plugin.AbstractFormPlugin;
import wens.pig.base.utils.VerificationUtil;

import java.util.regex.Pattern;

/**
 * Description:批次参数设置
 *
 * @author yaord
 * @date 18:47 2022/7/21
 */
public class BatchVisualParamBillPlugin extends AbstractFormPlugin {

    @Override
    public void propertyChanged(PropertyChangedArgs e) {
        String name = e.getProperty().getName();
        if ("wens_batchcolor".equals(name)){
            Object value = this.getModel().getValue("wens_batchcolor");
            if (value != null){
                boolean matches = Pattern.matches(VerificationUtil.HEX_PATTERN, String.valueOf(value));
                if (!matches){
                    String flag = this.getPageCache().get("flag");
                    if (StringUtil.isEmpty(flag)) {
                        this.getPageCache().put("flag", "true");
                        getView().showTipNotification("请填写正确格式颜色");
                        this.getModel().setValue("wens_batchcolor",null);
                    } else {
                        this.getPageCache().put("flag", "");
                    }
                }
            }
        }
    }
}
